// @ts-nocheck
export function getTimeFromDate(time: number) {
  const data = new Date(time);
  const minute =
    data.getMinutes() < 10 ? "0" + data.getMinutes() : data.getMinutes(); // 分钟
  const hour =
    (data.getHours() < 10 ? "0" + data.getHours() : data.getHours()) + ":"; // 小时
  const day =
    (data.getDate() < 10 ? "0" + data.getDate() : data.getDate()) + "   "; // 天
  const month =
    (data.getMonth() + 1 < 10
      ? "0" + (data.getMonth() + 1)
      : data.getMonth() + 1) + "-"; // 月
  const year = data.getFullYear() + "-"; // 年

  return year + month + day + hour + minute;
}

/**
 * 返回格式化后的日期
 *
 * @param (date,parttern)
 * @param pattern "yyyy.dd.mm"
 *
 * @return "2018.01.01"
 */

export function dateFormat(millionsTime, pattern) {
  const d = new Date();
  d.setTime(millionsTime);
  const date = {
    "M+": d.getMonth() + 1,
    "d+": d.getDate(),
    "h+": d.getHours(),
    "m+": d.getMinutes(),
    "s+": d.getSeconds(),
    "q+": Math.floor((d.getMonth() + 3) / 3),
    "S+": d.getMilliseconds(),
  };
  if (/(y+)/i.test(pattern)) {
    pattern = pattern.replace(
      RegExp.$1,
      (d.getFullYear() + "").substr(4 - RegExp.$1.length)
    );
  }
  for (const k in date) {
    if (new RegExp("(" + k + ")").test(pattern)) {
      pattern = pattern.replace(
        RegExp.$1,
        RegExp.$1.length == 1
          ? date[k]
          : ("00" + date[k]).substr(("" + date[k]).length)
      );
    }
  }
  return pattern;
}

export function dateYearToDate(createTime: string | number | Date) {
    const date = new Date(createTime)
    const Y = date.getFullYear() + '年'
    const M = date.getMonth() + '月'
    const D = date.getDate() + '日'
    const h = date.getHours() + ':'
    const m = date.getMinutes()
    return {
        yearToDate: Y + M + D,
        time: h + m
    }
}